package com.spring.shops.admin.controller.system;
import com.spring.shops.model.dto.SysMenuDTO;
import com.spring.shops.model.dto.SysUserDTO;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.model.vo.SysMenuVO;
import com.spring.shops.model.vo.SysRoleVO;
import com.spring.shops.service.MenuService;
import com.spring.shops.service.RoleService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//系统管理->菜单管理
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {
    @Autowired
    private MenuService menuService;

    /**
     * 获取所有的权限列表
     * @return
     */
    @GetMapping("/table")
    public ServerResponseEntityVoid<List<SysMenuVO>> table() {
        return menuService.table();
    }

    /**
     * 通过登陆用户的userId获取用户所拥有的菜单和权限
     */
    @GetMapping("/list")
    public ServerResponseEntityVoid<List<SysMenuVO>> list(){
        return menuService.list();
    }

    /**
     * 新增菜单数据
     * @param dto
     * @return
     */
    @PostMapping
    public ServerResponseEntityVoid save(@RequestBody SysMenuDTO dto){
        return menuService.save(dto);
    }

    /**
     * 根据菜单id获取信息
     * @param menuId
     * @return
     */
    @GetMapping("/info/{menuId}")
    public ServerResponseEntityVoid<SysMenuVO> getInfoById(@PathVariable Long menuId){
        return menuService.getInfoById(menuId);
    }

    /**
     * 更新菜单信息
     * @param dto
     * @return
     */
    @PutMapping
    public ServerResponseEntityVoid update(@RequestBody SysMenuDTO dto){
        return menuService.update(dto);
    }

    /**
     * 根据id删除数据
     * @param menuId
     * @return
     */
    @DeleteMapping("/{menuId}")
    public ServerResponseEntityVoid deleteById(@PathVariable Long menuId){
        return menuService.deleteById(menuId);
    }
}
